local skel = fk.CreateSkill {
  name = "emo__luomu",
}

skel:addEffect(fk.TargetSpecified, {
  anim_type = "offensive",
  can_trigger = function (self, event, target, player, data)
    if target == player and player:hasSkill(skel.name) and data.firstTarget and player:getMark("@emo__xueyan") > 0 then
      return table.find(data.use.tos, function (to)
        return to ~= player
      end) ~= nil
    end
  end,
  on_cost = function (self, event, target, player, data)
    local room = player.room
    if room:askToSkillInvoke(player, {skill_name = skel.name, prompt = "#emo__luomu-cost:::"..data.card.name}) then
      local targets = table.filter(data.use.tos, function (to)
        return to ~= player and not to:isNude()
      end)
      local tos = room:askToChoosePlayers(player, {
        targets = targets, min_num = 1, max_num = 1, skill_name = skel.name, cancelable = true,
        prompt = "#emo__luomu-choose",
      })
      if #tos > 0 then
        event:setCostData(self, {choice = "prey", tos = tos})
      else
        event:setCostData(self, {choice = "extra"})
      end
      return true
    end
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    room:removePlayerMark(player, "@emo__xueyan", 1)
    room:addPlayerMark(player, "emo__yangsan_used-turn", 1)
    if event:getCostData(self).choice == "prey" then
      local to = event:getCostData(self).tos[1]
      local cid = room:askToChooseCard(player, { target = to, skill_name = skel.name, flag = "he"})
      room:obtainCard(player, cid, false, fk.ReasonPrey, player, skel.name)
    else
      data.use.additionalEffect = (data.use.additionalEffect or 0) + 1
    end
  end,
})

skel:addEffect(fk.EventPhaseStart, {
  anim_type = "offensive",
  can_trigger = function (self, event, target, player, data)
    if target.phase == Player.Finish and player:hasSkill(skel.name) then
      return player:getMark("emo__yangsan_used-turn") > (2 * player.hp)
    end
  end,
  on_cost = function (self, event, target, player, data)
    if player.room:askToSkillInvoke(player, {skill_name = skel.name, prompt = "#emo__luomu-trick"}) then
      return true
    end
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local names = Fk:getAllCardNames("t")
    room:askToUseVirtualCard(player, {
      name = names, skill_name = skel.name, extra_data = {bypass_distances = true},
    })
  end,
})
skel:addLoseEffect(function (self, player, is_death)
  if not (player:hasSkill("emo__xueyan", true) or player:hasSkill("emo__yangsan", true) or player:hasSkill("emo__luomu", true)) then
    player.room:setPlayerMark(player, "@emo__xueyan", 0)
  end
end)

Fk:loadTranslationTable{
  ["emo__luomu"] = "落幕",
  [":emo__luomu"] = "当你使用牌指定其他角色后，你可以消耗1层血宴并选择一项：1.令此牌额外结算一次；2.获得一个目标一张牌；每名角色的结束阶段，若你本回合消耗的血宴层数不小于2X（X为你当前体力值），你可以视为使用一张任意普通锦囊牌。",
  ["#emo__luomu-cost"] = "落幕：你可以消耗1层“血宴”，令%arg额外结算，或获得目标一张牌",
  ["#emo__luomu-choose"] = "获得一个目标角色的一张牌（不选则令此牌额外结算1次）",
  ["#emo__luomu-trick"] = "落幕：你可以视为使用一张任意普通锦囊牌",

  ["$emo__luomu"] = "真美啊，你飞溅的鲜血",
}

return skel
